#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
signed main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int cishu;
    cin>>cishu;
    while(cishu--)
    {
        int n,m,l,V,cnt=0,max_=0,mcnt=0;
        bool tof=0;
        cin>>n>>m>>l>>V;
        vector<vector<int>> a(n+1,vector<int>(l+1));
        vector<bool> v(l+1);
        for(int i=1;i<=n;i++)
        {
            int d,vv,aa;
            cin>>d>>vv>>aa;
            max_=max(max_,d);
            bool toff=0;
            for(int j=d;j<=l&&vv>0;j++)
            {
                if(vv>V&&!toff)
                {
                    cnt++;
                    toff=1;
                }
                a[i][j]=vv;
                vv+=aa;
            }
        }
        for(int i=1;i<=m;i++)
        {
            int t;
            cin>>t;
            if(t>=max_&&!tof)
            {
                tof=1;
                mcnt++;
            }
            else if(t<max_) mcnt++;
            v[t]=1;
        }
        cout<<cnt<<' '<<mcnt;
    }
    return 0;
}
